$(function () {
    $("#page").load("/html/page.html");
    selectGroup();
});

function selectGroup() {
    let result = myAjax('/group/selectAll', 'post', {});
    let html = " <option value='0'>全部</option>";
    for (let i = 0; i < result.list.length; i++) {
        html += ' <option value="' + result.list[i].id + '">' + result.list[i].name + '</option>';
    }
    $("#team").html(html);
}

function searchAll() {
    let data = {};
    data.userName = $("#userName").val();
    data.team = $("#team").find("option:selected").text();
    data.outState = $("#outState").val();
    data.signDate = $("#signDate").val();
    data.pageNum = $.trim($("#pageNum").val());
    data.pageSize = $.trim($("#pageSize").val());
    let result = myAjax('/sign/selectOutAll', 'post', data);
    showData(result.list);
    $("#pageCount").html(result.number);
}

function showData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].updateTime==null){
            data[i].updateTime="暂无更改";
        }
        if (data[i].remark==null){
            data[i].remark="";
        }
        html += '   <tr> ' +
            '  <td><input type="checkbox" name="isCheck" value="' + data[i].id + '">' + data[i].id + '</td>\n' +
            '        <td>' + data[i].userName + '</td>\n' +
            '        <td>' + data[i].team + '</td>\n' +
            '        <td>' + data[i].outState + '</td>\n' +
            '        <td>' + data[i].signDate + '</td>\n' +
            '        <td>' + data[i].outTime + '</td>\n' +
            '        <td>' + data[i].updateTime + '</td>\n' +
            '        <td><input type="button" style="width: 60px;border-radius: 5px;' +
            'background-color: red" value="删除" onclick="del(' + data[i].id + ')">' +
            '         <input type="button" style="width: 60px;border-radius: 5px;' +
            'background-color: #5FB878" value="修改" onclick="edit(' + data[i].id + ',`' + data[i].userName + '`)"></td>' +
            '    </tr>';
    }
    $("#findAll").html(html);
}

function del(id) {
    layer.confirm("确定删除吗？","",function () {
        let result = myAjax("/sign/signOutDelete", "get", {id: id})
        if (result === 1) {
            layer.msg("删除成功");
            searchAll();
        }
    });
}

//点击修改按钮进行页面弹出，传递两个参数，一个小组id一个小组名字，然后动态赋值给弹出页面，后面添加成员要用到。
layui.use('layer');

function edit(id, name) {
    sessionStorage.setItem("signOutId", id);
    //弹出一个页面层
    let html = "<span id='signOutUserName'>" + name + "</span>"
    layer.open({
        type: 2,
        anim: 3,
        title: '' + html + '签到编辑',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/signOutEdit.html', 'no'],
    })
}

function add() {
    layer.open({
        type: 2,
        anim: 2,
        title: '请先选择要进行签退的小组',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/confirmTeamSignOut.html', 'no'],
    })
}
